#ifndef FILEUTILITIES_H
#define FILEUTILITIES_H

#include <QList>
#include <QPair>
#include <QSharedPointer>

class QDir;

#include "generatoroutputview.h"
#include "generatordata.h"
#include "hybridplugin.h"
#include "defines.h"

class FileUtilities
{
public:
    FileUtilities(GeneratorOutputView &outputView, GeneratorData &generatorData);

	bool updateMainFile();
    bool updateMainWindowFile();
    bool updateProjectFile(QString filename);
    void createWidgetResourceFile();
    bool createWidgetProjectFile(const QList< QSharedPointer<HybridPlugin> > &plugins);
    bool createPluginsProjectFile(const QList< QSharedPointer<HybridPlugin> > &plugins);
    bool configXmlToInfoPlistFile(WidgetType widgetType);
    bool directoryToInfoPlistFile();
    QString getMainHTMLFileFullPath();
    QString getWidgetIdentifier();


    /**
      * Finds a file recursively under a directory.
      *
      * @param dir under which the file is to be found, directly or
      *        indirectly
      *
      * @param fileName the name of the file to be found.
      *
      * @return the absolute path to the file, if found, empty string
      *         otherwise.
      */
    static QString findFile(const QDir    & dir,
                            const QString & fileName);


    /**
      * Makes sure that tmpDir exists and it is empty.
      */
    static bool clearUpDir(QDir tmpDir);


    /**
      * Unzips a widget file to a directory. Blocking (sync) call.
      *
      * @return true iff successful
      */
    static bool syncUnzipWidgetFile(const QString & wgzFile,
                                    const QString & unzipDir);
    /**
      * Figures out the app name(s) for a widget File.
      *
      * @param widgetFilePath path to a widget file or widget directory
      *
      * @return a pair of <app-name, app-display-name> values.
      */
    static QPair<QString, QString> sniffAppNames(const QString & widgetFilePath);

private:

    bool readTemplateFile(const QString &fileName, QString &fileContent, const QString &onErrorMessage);
    void processTemplateProjectFileLine(QString &templateFileLine);

    GeneratorOutputView &m_outputView;
    GeneratorData       &m_generatorData;
    QString             m_infoPlistFileNameNoSpaces;

};

#endif // FILEUTILITIES_H
